<?php


class EmsImageSizeTable extends Doctrine_Table
{
    public function getEspecificSize($width, $height, Doctrine_Query $q = null)
    {
        if (is_null($q))
        {
            $q = Doctrine_Query::create()
                ->from('EmsImageSize is');
        }

        $alias = $q->getRootAlias();

        $q->andWhere($alias .'.width = ?', $width)
            ->andWhere($alias .'.height = ?', $height);

        return $q->fetchOne();
    }

    public function getEnabledSizesQuery(Doctrine_Query $q = null)
    {
        if (is_null($q))
        {
            $q = Doctrine_Query::create()
                ->from('EmsImageSize is');
        }

        $alias = $q->getRootAlias();

        $q->andWhere($alias .'.is_enabled = ?', 1);

        return $q;
    }

    public function getEnabledSizes()
    {
        return $this->getEnabledSizesQuery()->execute();
    }

    public function getEspecificSizeIfIsEnabled($width, $height)
    {
        return $this->getEspecificSize($width, $height, $this->getEnabledSizesQuery());
    }

    public static function getInstance()
    {
        return Doctrine_Core::getTable('EmsImageSize');
    }
}